#include "nor_flash.h"

xdata u8 norflash_cmd[8];

void norflash_write(u32 addr,u8* buff,u16 len)
{
	sys_write_vp(CACHE_ADDR,buff,len);
	norflash_cmd[0]=NOR_FLASH_WRITE;
	
	norflash_cmd[1]=(addr>>16)&0xFF;
	norflash_cmd[2]=(addr>>8)&0xFF;
	norflash_cmd[3]=addr&0xFF;
	
	norflash_cmd[4]=(CACHE_ADDR>>8)&0xFF;
	norflash_cmd[5]=CACHE_ADDR&0xFF;
	
	norflash_cmd[6]=(len>>8)&0xFF;
	norflash_cmd[7]=len&0xFF;
	
	sys_write_vp(NOR_FLASH_ADDR,norflash_cmd,4);
	
	while(1)
	{
		sys_read_vp(NOR_FLASH_ADDR,norflash_cmd,2);
		if(norflash_cmd[0]==0)
			break;
		sys_delay_about_ms(1);
	}
	

}


void norflash_read(u32 addr,u8* buff,u16 len)
{
	norflash_cmd[0]=NOR_FLASH_READ;
	
	norflash_cmd[1]=(addr>>16)&0xFF;
	norflash_cmd[2]=(addr>>8)&0xFF;
	norflash_cmd[3]=addr&0xFF;
	
	norflash_cmd[4]=(CACHE_ADDR>>8)&0xFF;
	norflash_cmd[5]=CACHE_ADDR&0xFF;
	
	norflash_cmd[6]=(len>>8)&0xFF;
	norflash_cmd[7]=len&0xFF;
	
	sys_write_vp(NOR_FLASH_ADDR,norflash_cmd,4);
	
	while(1)
	{
		sys_read_vp(NOR_FLASH_ADDR,norflash_cmd,2);
		if(norflash_cmd[0]==0)
			break;
		sys_delay_about_ms(1);
	}
	sys_read_vp(CACHE_ADDR,buff,len);

}






